<template>
  <div class="vote-result-bg">
    <div class="custom-menu-bar">
      <div v-for="item in menuList" :key="item.index" :class="['custom-menu-item', {active: active === item.index}]" @click="go(item.path)">
        {{ item.label }}
      </div>
    </div>
    <el-menu :default-active="activeTab" mode="horizontal" background-color="#444" text-color="#fff" active-text-color="#b6d43a" class="vote-tab-menu">
      <el-menu-item v-for="(item, idx) in votes" :key="item.number" :index="(idx+1)+''" @click="selectVote(idx)">{{ item.name }}</el-menu-item>
    </el-menu>
    <div class="vote-detail-wrap">
      <el-card class="vote-img-card">
        <img :src="getVoteImg(current)" class="vote-img" />
      </el-card>
      <el-card class="vote-detail-card">
        <div class="vote-detail-title">{{ current.name }}</div>
        <div class="vote-detail-info">
          <div class="info-row"><span>项目编号：</span>{{ current.number }}</div>
          <div class="info-row"><span>学号：</span>{{ current.stuId }}</div>
          <div class="info-row"><span>姓名：</span>{{ current.stuName }}</div>
          <div class="info-row"><span>投票数量：</span>{{ current.votes }}</div>
          <div class="info-row"><span>投票排名：</span>{{ current.rank }}</div>
        </div>
      </el-card>
    </div>
    <div class="vote-action-bar"></div>
  </div>
</template>
<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter();
const menuList = [
  { path: '/', label: '首页', index: '1' },
  { path: '/projects', label: '项目展示', index: '2' },
  { path: '/vote-result', label: '投票结果', index: '3' },
  { path: '/post-platform', label: '互动平台', index: '4' },
  { path: '/notices', label: '公告通知', index: '5' },
  { path: '/user-center', label: '个人中心', index: '6' },
  { path: '/admin', label: '后台管理', index: '7' },
];
const votes = ref([
  {
    number: 'P001',
    name: '项目名称1',
    img: '/picture/项目展示1 2025-06-21 012026.png',
    stuId: '学号1',
    stuName: '李明1',
    votes: 12,
    rank: 1,
  },
  {
    number: 'P002',
    name: '项目名称2',
    img: '/picture/项目展示2 2025-06-21 012139.png',
    stuId: '学号2',
    stuName: '李明2',
    votes: 8,
    rank: 2,
  },
]);
const active = ref('3');
const activeTab = ref('1');
const currentIdx = ref(0);
const current = ref(votes.value[0]);
function selectVote(idx) {
  currentIdx.value = idx;
  current.value = votes.value[idx];
  activeTab.value = (idx+1)+'';
}
function getVoteImg(vote) {
  if (vote.img) return vote.img;
  return `https://api.dicebear.com/6.x/identicon/svg?seed=${vote.number}`;
}
function go(path) {
  router.push(path);
  const found = menuList.find(item => item.path === path);
  if (found) active.value = found.index;
}
</script>
<style scoped>
.vote-result-bg {
  min-height: 100vh;
  background: #ededed;
  padding-bottom: 32px;
}
.custom-menu-bar {
  width: 100vw;
  background: #000;
  display: flex;
  align-items: center;
  padding: 0;
  margin: 0;
  height: 36px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.custom-menu-item {
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  padding: 0 18px;
  height: 36px;
  line-height: 36px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  background: transparent;
  border: none;
  outline: none;
  margin: 0;
  border-radius: 0;
  box-shadow: none;
  user-select: none;
}
.custom-menu-item.active {
  background: #fff;
  color: #111;
  font-weight: bold;
  border-bottom: 2px solid #fff;
}
.vote-tab-menu {
  margin: 0 auto;
  max-width: 900px;
  border-radius: 0 0 8px 8px;
  margin-top: 18px;
  margin-bottom: 0;
}
.vote-detail-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 40px;
  margin: 40px auto 0 auto;
  max-width: 900px;
}
.vote-img-card {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 4px 16px #e0e0e0;
  padding: 32px 24px;
  min-width: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.vote-img {
  width: 220px;
  height: 220px;
  object-fit: cover;
  border-radius: 16px;
  box-shadow: 0 2px 8px #d0d0d0;
}
.vote-detail-card {
  flex: 1;
  min-width: 320px;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 4px 16px #e0e0e0;
  padding: 0 0 24px 0;
}
.vote-detail-title {
  background: #554c3c;
  color: #fff;
  font-size: 22px;
  font-weight: bold;
  padding: 12px 0;
  border-radius: 12px;
  margin: 18px 0 12px 0;
  width: 90%;
  text-align: center;
  letter-spacing: 2px;
}
.vote-detail-info {
  width: 90%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 16px;
  color: #333;
  background: #fafafc;
  border-radius: 8px;
  padding: 16px 18px;
  box-shadow: 0 1px 4px #f0f0f0;
}
.info-row {
  display: flex;
  border-bottom: 1px dashed #e0e0e0;
  padding: 4px 0;
}
.info-row:last-child {
  border-bottom: none;
}
.info-row span {
  min-width: 90px;
  color: #888;
  font-weight: 500;
}
.vote-action-bar {
  width: 100%;
  height: 24px;
  background: #b6d43a;
  border-radius: 0 0 16px 16px;
  max-width: 900px;
  margin: 0 auto;
  margin-top: 12px;
}
</style> 